# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>

pkgname=pam_wrapper
pkgver=1.0.7
pkgrel=2
pkgdesc="Tool to test PAM applications and PAM modules"
url="https://cwrap.org/pam_wrapper.html"
arch=(x86_64)
license=(GPL3)
depends=(pam python)
makedepends=(git cmake cmocka doxygen graphviz)
provides=(libpam_wrapper.so libpamtest.so)
_commit=61283c98a49204b7bc4d2750fe506e877e31a214  # tags/pam_wrapper-1.0.7^0
source=("git://git.samba.org/pam_wrapper.git#commit=$_commit"
        2.patch)
sha256sums=('SKIP'
            '105e114a986fe25e20fb58539b6b7a878af8d71211fa88cb66132fd6b88fb7dc')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^pam_wrapper-//;s/_/./g;s/-/+/g'
}

prepare() {
  cd $pkgname

  # https://gitlab.com/cwrap/pam_wrapper/-/merge_requests/2
  git apply -3 ../2.patch
}

build() {
  cmake -H$pkgname -Bbuild \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DMAN_INSTALL_DIR=/usr/share/man \
    -DUNIT_TESTING=true
  cmake --build build
  cmake --build build --target doc
}

check() {
  cmake --build build --target test
}

package() {
  DESTDIR="$pkgdir" cmake --build build --target install

  mkdir -p "$pkgdir/usr/share/doc"
  cp -a build/doc/html "$pkgdir/usr/share/doc/$pkgname"
  cp -a build/doc/man/man3 "$pkgdir/usr/share/man"
}
